


//
//  MyCollectShopTabVC.m
//  BusinessMarket
//
//  Created by Michael Li on 2018/11/1.
//  Copyright © 2018年 Michael Li. All rights reserved.
//

#import "MyCollectShopTabVC.h"
#import "MyShopNormalCell.h"
#import "ShopSubModel.h"
#import "MyCollectShopContentVC.h"
#import "ShopModel.h"
@interface MyCollectShopTabVC ()<DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
@property(nonatomic,strong) NSDictionary  *dict;
@property(nonatomic,strong) NSMutableArray *dataMuta;
@property(nonatomic,assign) NSInteger id;
@property(nonatomic,assign) NSInteger uid;
@property(nonatomic,assign) NSInteger pageSize;
@property(nonatomic,assign) NSInteger pageNumber;
@property(nonatomic,assign) NSInteger rid;
@property(nonatomic,assign) NSInteger did;
@property(nonatomic,assign) NSInteger aid;
@property(nonatomic,assign) NSInteger sid;
@end
static NSString *identifierOne = @"MyShopNormalCell";
@implementation MyCollectShopTabVC
-(NSMutableArray *)dataMuta
{
    if (!_dataMuta) {
        _dataMuta = [NSMutableArray array];
    }
    return _dataMuta;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self reloadInternetData];
    [self.tableView registerNib:[UINib nibWithNibName:@"MyShopNormalCell" bundle:nil] forCellReuseIdentifier:identifierOne];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(collectionShop:) name:@"collectionShop" object:nil];
    self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refresh)];
    self.tableView.mj_header = header;
    [header beginRefreshing];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(collectShop:) name:@"collectShop" object:nil];
}
#pragma mark-代理:接受店铺收藏
-(void)collectShop:(NSNotification *)info
{
    [self.tableView reloadData];
}

-(void)collectionShop:(NSNotification *)info
{
    NSDictionary *dict = info.userInfo;
    NSArray *date = [dict objectForKey:@"date"];
    XLog(@"dict:%@",dict);
    NSInteger empty = [EmptyModel stringIsNullOrEmpty:date];
    XLog(@"empty:%ld",(long)empty);
     if (date.count||empty !=1) {
         for (NSDictionary *dict in date) {
             ShopSubModel *model =[ShopSubModel mj_objectWithKeyValues:dict];
             [self.dataMuta addObject:model];
             
         }
         [self.tableView.mj_footer endRefreshing];
     }else {
         self.tableView.emptyDataSetSource = self;
         self.tableView.emptyDataSetDelegate = self;
     }
    if (self.dataMuta.count) {
        MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(reloadMore)];
        self.tableView.mj_footer = footer;
                [footer setTitle:[NSBundle bundleLocalizedStringForKey:@"footerTitle"]
 forState:MJRefreshStateNoMoreData];
                footer.stateLabel.font = [UIFont systemFontOfSize:12];
                footer.stateLabel.textColor = [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1];
        if (date.count< 10) {
            self.tableView.mj_footer.state = MJRefreshStateNoMoreData;
        }
    }
    [self.tableView reloadData];
    [self.tableView.mj_header endRefreshing];
    [WSProgressHUD dismiss];
}
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
    UIImage *image = [UIImage imageNamed:@"empty"];
    return image;
}
- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
    NSString *title = [NSBundle bundleLocalizedStringForKey:@"noData"];
    NSDictionary *attributes = @{
                                 NSFontAttributeName:[UIFont boldSystemFontOfSize:14],
                                 NSForegroundColorAttributeName:kLabel102Color
                                 };
    return [[NSAttributedString alloc] initWithString:title attributes:attributes];
}
-(void)qingqiusibai:(NSNotification *)info
{
    NSDictionary *dict = info.userInfo;
    XLog(@"dict:%@",dict);
    self.tableView.mj_footer.state = MJRefreshStateNoMoreData;
    [self.tableView.mj_header endRefreshing];
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
-(void)refresh
{
    self.dataMuta = nil;
    self.pageNumber = 1;
    self.pageSize = 10;
    self.uid = 1;
    self.id = 1;
    [self reloadInternetData];
}
-(void)reloadMore
{
    [WSProgressHUD setProgressHUDIndicatorStyle:WSProgressHUDIndicatorBigGray];
    [WSProgressHUD show];
    self.pageNumber ++;
    [self reloadInternetData];
    
}
-(void)reloadInternetData {
    NSString *pageNums = [NSString stringWithFormat:@"%ld",self.pageNumber];
    NSString *pageSizes = [NSString stringWithFormat:@"%ld",self.pageSize];
    self.dict = @{
                  @"uid":[UserDefaultsHelper readUid],
                  @"pageNumber":pageNums,
                  @"pageSize":pageSizes,
                  @"token":[UserDefaultsHelper readToken]
                  };
    XLog(@"dict:%@",self.dict);
    [CustomeManager POSTWithURLIndex:27 parameters:self.dict  success:^(NSDictionary *dict) {
        
    } failure:^(NSError *error) {
        
    }];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataMuta.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    
    MyShopNormalCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierOne forIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    ShopSubModel *model = self.dataMuta[indexPath.section];
    cell.shopModel = model;
    return cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    ShopSubModel *model = self.dataMuta[indexPath.section];
    
    if (self.returnValueBlock) {
        self.returnValueBlock(model);
    };
}


@end
